<?php

namespace app\admin\controller;


class DynamicCategory extends Common {


	//文章分类表
	private $table_admin = "";

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
		$this->table_admin = db('dynamic_category');
	}

	public function index(){
		$data = $this->table_admin->paginate(10);
		$this->assign('data',$data);
		return 	$this->fetch();
	}

	/*
	 * 添加或修改
	 * */
	public function add(){
		if(request()->isAjax()) {
			$title = input('title');
//			halt($file);
			if(!$title)
				$this->error('标题为空！');
			$data['category_name'] = $title;
			$id = input('id');
			if(empty($id)){
				//添加
				 $this->table_admin->insert($data);
			}else{
//				$data['id'] = input('id');
				//修改
				$id = input('id');
				$this->table_admin->where('id',$id)->update($data);
//				$sql = $this->table_admin->getLastSql();
//				$this->success($sql);
			}
			$this->success("操作成功!",url('DynamicCategory/index'));
		}
		return $this->fetch();
	}

	public function edit(){
		$id = input('id');
		$data = $this->table_admin->where('id',$id)->find();
		$this->assign('data',$data);
		return $this->fetch();
	}

	public function delete(){
		$id = input("id");
		if(!$id) $this->error('参数有误');
		$da=$this->table_admin->where("id='$id'")->find();
		if(!$da) $this->error('数据不存在');
		$res=$this->table_admin->where("id='$id'")->delete();
		if(!$res) $this->error('删除失败');
		$this->success("删除成功!",url('DynamicCategory/li'));
	}
}